﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm.TransactSql;
using VK.Casemeet.Pages;
using VK.Comm;

namespace VK.Casemeet.Web.Admin.Pages
{
    public partial class CustomPageList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="页面列表",Url="#"}
            };

            if (!IsPostBack)
            {
                LoadData(false);
            }
        }

        protected void LoadData(bool isCondition)
        {
            IList<Condition> conditionlst = new List<Condition>();
            aspNetPager.RecordCount = CustomPageBLL.GetCustomPageCount(conditionlst);
            rptCustomPage.DataSource = CustomPageBLL.GetCustomPageList(aspNetPager.StartRecordIndex, aspNetPager.EndRecordIndex, conditionlst, null, SortMode.Desc);
            rptCustomPage.DataBind();
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        protected void aspNetPager_PageChanged(object sender, EventArgs e)
        {
            LoadData(true);
        }

        protected void rptCustomPage_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.CommandName == "Delete")
                {
                    switch (CustomPageBLL.DeleteCustomPage(int.Parse(e.CommandArgument.ToString())))
                    {
                        case 0:
                            Message.Msg(this.Page, "操作失败!", MessageType.Failure);
                            break;
                        case 1:
                            Message.Msg(this.Page, "操作成功!", MessageType.Success);
                            break;
                        case 2:
                            Message.Msg(this.Page, "系统页面不能被删除!", MessageType.Failure);
                            break;
                    }
                    LoadData(true);
                }
            }
        }
    }
}